
package card;

import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 *
 * @author DA5221-GRP63
 */

public class storePanel extends JPanel {
    public storePanel(String id, eventFrame ef) {
        try {
            this.eFrame = ef;
            this.CardID = id;
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setLayout(null);
        jLabel1.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 18));
        jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel1.setText("Name:");
        jLabel1.setBounds(new Rectangle(80, 70, 76, 25));
        staticMessage sm = new staticMessage(CardID);
        jLabel2.setText(staticMessage.userName);
        jLabel2.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 18));
        jLabel2.setBounds(new Rectangle(181, 65, 178, 27));
        jLabel2.setForeground(Color.blue);
        jLabel3.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 18));
        jLabel3.setText("Deposit:");
        jLabel3.setBounds(new Rectangle(80, 131, 90, 24));
        jTextField1.setText("");
        jTextField1.setBounds(new Rectangle(187, 130, 126, 24));
        jTextField1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
                jTextField1_actionPerformed(e);
            }
        });
        jButton1.setBounds(new Rectangle(93, 207, 75, 22));
        jButton1.setFont(new java.awt.Font("Times New Roman", Font.PLAIN, 11));
        jButton1.setText("Comfirm");
        jButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
                jButton1_actionPerformed(e);
            }
        });
        jButton2.setBounds(new Rectangle(230, 207, 75, 22));
        jButton2.setFont(new java.awt.Font("Times New Roman", Font.PLAIN, 11));
        jButton2.setText("Reset");
        jButton2.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
                jButton2_actionPerformed(e);
            }
        });

        this.add(jLabel1);
        this.add(jLabel3);
        this.add(jLabel2);
        this.add(jTextField1);
        this.add(jButton2);
        this.add(jButton1);

        con = cardConnect.getconn();
    }
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jL1 = new JLabel();
    JLabel jL2 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jB = new JButton();
    public JFrame jf1;
    eventFrame eFrame;
    String CardID;
    Connection con;
    String UserName;
    Statement getUpdate;
    Statement getInsert;
    eventFrame eventFrame;
    String updateString;
    String insertString;

    public void jButton1_actionPerformed(ActionEvent e) {
        this.setVisible(false);
        jf1 = new JFrame("Satement");
        jf1.setBounds(100, 50, 400, 300);
        jf1.setVisible(true);
        jL1.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 18));
        jL1.setText("Your balance now is:");
        jL1.setBounds(new Rectangle(90, 30, 200, 25));
        jB.setBounds(new Rectangle(150, 207, 75, 22));
        jB.setFont(new java.awt.Font("Times New Roman", Font.PLAIN, 11));
        jB.setText("Comfirm");
        jB.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
                jf1.dispose();
            }
        });

        jf1.add(jL1);
        jf1.add(jB);
        try {
            getUpdate = con.createStatement();
            String getAmount = "SELECT EventMoney FROM card WHERE CardID = '" + Integer.parseInt(CardID) + "'";
            double amount = 0;
            ResultSet res = getUpdate.executeQuery(getAmount);
            if (res.next()) {
                amount = Double.parseDouble(res.getString(1));
            }
            System.out.println(amount);
            double newAmount = amount + Double.parseDouble(jTextField1.getText());
            System.out.println(newAmount);
            updateString = "UPDATE card SET EventMoney= '" + newAmount + "' Where CardID='" + Integer.parseInt(CardID) + "'";
            getUpdate.executeUpdate(updateString);

        } catch (SQLException ex) {
            System.out.println("Datebase Wrong！");
        } finally {
        }
        staticMessage sm = new staticMessage(CardID);
        jL2.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 18));
        jL2.setBounds(new Rectangle(110, 45, 150, 27));
     
        jL2.setForeground(Color.blue);

        jL2.setText(staticMessage.yue);

        jf1.add(jL2);

    }

    public void jButton2_actionPerformed(ActionEvent e) {
        jTextField1.setText(null);
    }

    public void jTextField1_actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
    }
}

